function css(targetObj, cssObj) {

    var str = targetObj.getAttribute("style") ? targetObj.getAttribute("style") : "";

    for(var i in cssObj) {

        str += i + ":" + cssObj[i] + ";";

    }

    targetObj.style.cssText = str;

}
/*-------请假-----------*/

function showQingJia() {
    $.getJSON("/wxw/QingJia",function (data) {
        $(data).each(function (i,v) {
            $(".QJType").append("<option value='"+v.id+"'>"+v.type+"</option>")
        })
    })
}
function TinaShu() {
    let shijian1=$(".wxw-date1").val();
    let shijian2=$(".wxw-date2").val();
    let json={
        shiJian1:shijian1,
        shiJian2:shijian2
    }
    $.getJSON("/wxw/TianShu",json,function (data) {
        if (data<=0){
            layer.alert("请假天数不正确", {icon: 5})
            return;
        }else{
            $(".wxw-TianShu").val(data)
        }
    })
}
function shenPi() {
    $.getJSON("/wxw/selShen",function (data) {
        $(data).each(function (i,v) {
            $(".shenpi").append("<option>"+v+"</option>");
        })

    })
}

function QingJiaSave() {
    let shijian1=$(".wxw-date1").val();
    let shijian2=$(".wxw-date2").val();
    let QJType=$(".QJType").val();
    let shiyou=$(".shiyou").val();
    let shenpi=$(".shenpi").val();
    var now = new Date();
    var day = ("0" + now.getDate()).slice(-2);
    var month = ("0" + (now.getMonth() + 1)).slice(-2);
    var date1 = now.getFullYear()+"-"+(month)+"-"+(day) ;

    if (shijian1==""){
        layer.tips('请选择开始时间', '.wxw-date1', {
            tips: 4
        });
        return
    }
    if (shijian1<date1){
        layer.tips('请选择正确时间', '.wxw-date1', {
            tips: 4
        });
        return;
    }
    if (shijian2==""){
        layer.tips('请选择结束时间', '.wxw-date2', {
            tips: 4
        });
        return
    }
    if (QJType==-1){
        layer.tips('请选择请假类型', '.QJType', {
            tips: 4
        });
        return
    }
    if(shiyou==""){
        layer.tips('请输入请假事由', '.shiyou', {
            tips: 4
        });
        return
    }
    if(shenpi==-1){
        layer.tips('请选择审批人', '.shenpi', {
            tips: 3
        });
        return
    }
    let json = {
        begintime:shijian1,
        endtime:shijian2,
        d_id:QJType,
        reason:shiyou,
        approver:shenpi
    }
    console.log(json)
    $.getJSON("/wxw/QingJiaSave",json,function (data) {
        if (data){
            layer.alert('操作成功', {icon: 6});
        }else{
            layer.alert('操作失败', {icon: 5});
        }
        setTimeout("window.location.href='/to/toQingJia'",1000);
    })

}

function QingJiaSave2() {
    let shijian1=$(".wxw-date1").val();
    let shijian2=$(".wxw-date2").val();
    let QJType=$(".QJType").val();
    let shiyou=$(".shiyou").val();
    let shenpi=$(".shenpi").val();
    var now = new Date();
    var day = ("0" + now.getDate()).slice(-2);
    var month = ("0" + (now.getMonth() + 1)).slice(-2);
    var date1 = now.getFullYear()+"-"+(month)+"-"+(day) ;

    if (shijian1==""){
        layer.tips('请选择开始时间', '.wxw-date1', {
            tips: 4
        });
        return
    }
    if (shijian1<date1){
        layer.tips('请选择正确时间', '.wxw-date1', {
            tips: 4
        });
        return;
    }
    if (shijian2==""){
        layer.tips('请选择结束时间', '.wxw-date2', {
            tips: 4
        });
        return
    }
    if (QJType==-1){
        layer.tips('请选择请假类型', '.QJType', {
            tips: 4
        });
        return
    }
    if(shiyou==""){
        layer.tips('请输入请假事由', '.shiyou', {
            tips: 4
        });
        return
    }
    if(shenpi==-1){
        layer.tips('请选择审批人', '.shenpi', {
            tips: 3
        });
        return
    }
    let json = {
        begintime:shijian1,
        endtime:shijian2,
        d_id:QJType,
        reason:shiyou,
        approver:shenpi
    }
    console.log(json)
    $.getJSON("/wxw/QingJiaSave",json,function (data) {
        if (data){
            layer.alert('操作成功', {icon: 6});
        }else{
            layer.alert('操作失败', {icon: 5});
        }
        setTimeout("window.location.href='/to/qingjiajilu'",1000);
    })

}

/*--------出差----------*/
function showChuChai() {
    $.getJSON("/wxw/ChuChai",function (data) {
        $(data).each(function (i,v) {
            $(".CCType").append("<option value='"+v.id+"'>"+v.type+"</option>")
        })
    })
}

function saveChuChai() {
    let shijian3=$(".wxw-date3").val();
    let shijian4=$(".wxw-date4").val();
    let chuCai=$(".chuCai").val();
    let shiYou2=$(".shiYou2").val();
    let CCType=$(".CCType").val();
    let renWu=$(".renWu").val();
    let jinE=$(".jinE").val();
    let shenpi=$(".shenpi").val();
    var now = new Date();
    var day = ("0" + now.getDate()).slice(-2);
    var month = ("0" + (now.getMonth() + 1)).slice(-2);
    var date1 = now.getFullYear()+"-"+(month)+"-"+(day) ;

    if (shijian3==""){
        layer.tips('请选择出差时间', '.wxw-date3', {
            tips: 4
        });
        return
    }
    if (shijian3<date1){
        layer.tips('请选择正确时间', '.wxw-date3', {
            tips: 4
        });
        return;
    }
    if (shijian4==""){
        layer.tips('请选择结束时间', '.wxw-date4', {
            tips: 4
        });
        return
    }
    if (chuCai==""){
        layer.tips('请填写出差地点', '.chuCai', {
            tips: 4
        });
        return
    }
    if (CCType==-1){
        layer.tips('选择交通工具', '.CCType', {
            tips: 4
        });
        return
    }
    if (shiYou2==""){
        layer.tips('请填写出差事由', '.shiYou2', {
            tips: 4
        });
        return
    }
    if (renWu==""){
        layer.tips('请填写工作任务', '.renWu', {
            tips: 4
        });
        return
    }
    if (jinE==""){
        layer.tips('请填写借款金额', '.jinE');
        return
    }
    if (isNaN(jinE)){
        layer.tips('借款金额必须是数字', '.jinE');
        return
    }
    if (jinE<=0){
        layer.tips('借款金额不能小于0', '.jinE');
        return
    }
    if(shenpi==-1){
        layer.tips('请选择审批人', '.shenpi', {
            tips: 3
        })
        return
    }
    let json = {
        begintime:shijian3,
        endtime:shijian4,
        d_id:CCType,
        site: chuCai,
        reason:shiYou2,
        mission:renWu,
        money:jinE,
        approver:shenpi
    }
    console.log(json)
    $.getJSON("/wxw/ChuCaiSave",json,function (data) {
        if (data){
            layer.alert('操作成功', {icon: 6});
        }else{
            layer.alert('操作失败', {icon: 5});
        }
        setTimeout("window.location.href='/to/toChuChai'",1000);
    })
}

function saveChuChai2() {
    let shijian3=$(".wxw-date3").val();
    let shijian4=$(".wxw-date4").val();
    let chuCai=$(".chuCai").val();
    let shiYou2=$(".shiYou2").val();
    let CCType=$(".CCType").val();
    let renWu=$(".renWu").val();
    let jinE=$(".jinE").val();
    let shenpi=$(".shenpi").val();
    var now = new Date();
    var day = ("0" + now.getDate()).slice(-2);
    var month = ("0" + (now.getMonth() + 1)).slice(-2);
    var date1 = now.getFullYear()+"-"+(month)+"-"+(day) ;

    if (shijian3==""){
        layer.tips('请选择出差时间', '.wxw-date3', {
            tips: 4
        });
        return
    }
    if (shijian3<date1){
        layer.tips('请选择正确时间', '.wxw-date3', {
            tips: 4
        });
        return;
    }
    if (shijian4==""){
        layer.tips('请选择结束时间', '.wxw-date4', {
            tips: 4
        });
        return
    }
    if (chuCai==""){
        layer.tips('请填写出差地点', '.chuCai', {
            tips: 4
        });
        return
    }
    if (CCType==-1){
        layer.tips('选择交通工具', '.CCType', {
            tips: 4
        });
        return
    }
    if (shiYou2==""){
        layer.tips('请填写出差事由', '.shiYou2', {
            tips: 4
        });
        return
    }
    if (renWu==""){
        layer.tips('请填写工作任务', '.renWu', {
            tips: 4
        });
        return
    }
    if (jinE==""){
        layer.tips('请填写借款金额', '.jinE');
        return
    }
    if (isNaN(jinE)){
        layer.tips('借款金额必须是数字', '.jinE');
        return
    }
    if (jinE<=0){
        layer.tips('借款金额不能小于0', '.jinE');
        return
    }
    if(shenpi==-1){
        layer.tips('请选择审批人', '.shenpi', {
            tips: 3
        })
        return
    }
    let json = {
        begintime:shijian3,
        endtime:shijian4,
        d_id:CCType,
        site: chuCai,
        reason:shiYou2,
        mission:renWu,
        money:jinE,
        approver:shenpi
    }
    console.log(json)
    $.getJSON("/wxw/ChuCaiSave",json,function (data) {
        if (data){
            layer.alert('操作成功', {icon: 6});
        }else{
            layer.alert('操作失败', {icon: 5});
        }
        setTimeout("window.location.href='/to/chachaijilu'",1000);
    })
}

function guanbi() {
    window.location.href="/to/chachaijilu";
}
function guanbi2() {
    window.location.href="/to/qingjiajilu";
}
